package com.server.questionbank.snframe.controller.Login;

import com.server.questionbank.snframe.domain.VerificationCode.ImageCode;
import com.server.questionbank.snframe.domain.VerificationCode.SmsCode;
import com.server.questionbank.snframe.domain.ResDTO.ResponseResult;
import com.server.questionbank.snframe.service.VerificationCode.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.io.IOException;

@RestController
@RequestMapping("/code")
public class VerificationCodeController {
    @Autowired
    private VerificationCodeService verificationCode;

    @PostMapping("/image")
    public ResponseResult<ImageCode> getImageCode() throws IOException, FontFormatException {
        return verificationCode.getImageCode();
    }

    @PostMapping("/sms")
    public ResponseResult<String> sendSmsCode(@RequestBody SmsCode smsCode) {
        // 校验图片验证码
        ResponseResult<String> imageCodeResult = verificationCode.checkImageCode(smsCode.getImageCode());
        if(imageCodeResult.getCode() != 200) return imageCodeResult;

        ResponseResult<String> sendSmsCodeResult = verificationCode.sendSmsCode(smsCode.getPhoneNumber());
        // 发送短信验证码
        return sendSmsCodeResult;
    }
}
